package com.chen.config;

import com.chen.annotation.support.WxLoginUserHandlerMethodArgumentResolver;
import com.chen.interceptor.WxLoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;
import java.util.concurrent.Executor;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private WxLoginInterceptor wxLoginInterceptor;

    @Autowired
    private WxLoginUserHandlerMethodArgumentResolver handlerMethodArgumentResolver;

    @Autowired
    @Qualifier("fluxStream")
    private Executor executor;

    @Override
    public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
        configurer.setTaskExecutor((AsyncTaskExecutor)executor);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(wxLoginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/wx/login");
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
       resolvers.add(handlerMethodArgumentResolver);
    }


}
